package com.jiangSheng.mall.app.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.jiangSheng.mall.app.bean.ReceiverAddress;
import com.jiangSheng.mall.app.services.ReceiverAddressServices;
import com.jiangSheng.mall.app.utils.CommonResult;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@RestController
@Api("收货地址的方法")
@RequestMapping("/receiverAddress")
public class ReceiverAddressController {
	
	@Autowired
	private ReceiverAddressServices receiverAddressServices;
	
	@ApiOperation("添加收货地址")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<Integer> add(@RequestBody ReceiverAddress address) {
        int flag = receiverAddressServices.add(address);
        if (flag > 0) {
            return CommonResult.success(flag);
        }
        return CommonResult.failed();
    }

	@ApiOperation("修改收货地址")
    @RequestMapping(value = "/alter", method = RequestMethod.PUT)
    @ResponseBody
    public CommonResult<Integer> alter(@RequestBody ReceiverAddress address) {
        int flag = receiverAddressServices.alter(address);
        if (flag > 0) {
            return CommonResult.success(flag);
        }
        return CommonResult.failed();
    }
	
	@ApiOperation("删除收货地址")
    @RequestMapping(value = "/remove/{id}", method = RequestMethod.DELETE)
    @ResponseBody
    public CommonResult<Integer> remove(@PathVariable Integer id) {
        int flag = receiverAddressServices.remove(id);
        if (flag > 0) {
            return CommonResult.success(flag);
        }
        return CommonResult.failed();
    }
	
	@ApiOperation("显示所有收货地址")
    @RequestMapping(value = "/getList", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<ReceiverAddress>> getList() {
        List<ReceiverAddress> addressList = receiverAddressServices.getList();
        return CommonResult.success(addressList);
    }
	
	@ApiOperation("显示一个收货地址")
    @RequestMapping(value = "/getOneAddress/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<ReceiverAddress> getOneAddress(@PathVariable Integer id) {
        ReceiverAddress addressList = receiverAddressServices.getOneAddress(id);
        return CommonResult.success(addressList);
    }
	
}
